home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15156 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  50 lines

  1. Path: news.gate.net!bftsi0!joe
  2. From: joe@bftsi0.UUCP (Joe Foster of Borg)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: how to reposition cursor to start of line using cout?
  5. Message-ID: <6508@bftsi0.UUCP>
  6. Date: 3 Apr 96 21:54:35 GMT
  7. References: <nh68bie2ac.fsf@paralysys>
  8. Organization: Barbara Foster Tax Service, Inc.
  9.  
  10. In article <nh68bie2ac.fsf@paralysys>, nasser@paralysys (Nasser Abbasi) writes:
  11.  
  12. > hi,
  13.  
  14. > looking at the io stream classes I can't seem to find a way
  15. > to move the cursor backward.
  16.  
  17. > What I want to do is say display a counter (using cout), and as 
  18. > the program runs, the counter increaes in value, and I want to 
  19. > print the new value,
  20.  
  21. > But I do not want to do this next print on a new line, I want to 
  22. > overwrite the old one, this means I need to move the cursor to 
  23. > start of line to be able to do this.
  24.  
  25. > any one knows a  way to do?
  26.  
  27. > thanks!
  28. > Nasser
  29.  
  30. Flush the output buffer and output a '\r' (ASCII 13). Example:
  31.  
  32. #include <iostream.h>
  33.  
  34. extern "C" long nap(long msec);
  35.  
  36. main()
  37. {
  38.     for (int i = 0; i < 100; i++) {
  39.         cout << "\ri = " << i << flush;
  40.         sleep(1);
  41.     }
  42.     cout << endl;
  43.     return 0;
  44. }
  45.  
  46. -- 
  47. Joe Foster (joe@bftsi0.gate.net or joe%bftsi0@uunet.uu.net)
  48. WARNING: I cannot be held responsible for the above        They're   coming  to
  49. because  my cats have  apparently  learned to type.        take me away, ha ha!
  50.